/**   
 * @Title: LotteryRecordAgp.java 
 * @Package com.esun.cheetah.view.personal.lotteryrecord.LotteryRecordAgp
 * @Description: (购彩记录ActivityGroup 承载4个购彩记录列表) 
 * @author 孔祥攀 <br/>
 * @date 2012-4-13 下午2:05:57
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.cheetah.view.personal.lotteryrecord;

import android.app.Activity;
import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TabWidget;

import com.esun.cheetah.R;
import com.esun.cheetah.config.Config;
import com.esun.cheetah.config.Language;
import com.esun.cheetah.network.ConnectionChangeReceiver;
import com.esun.cheetah.view.personal.sportlotteryfootball.SportteryFootballAgp;

/**
 * 
 * @Package com.esun.cheetah.view.personal.lotteryrecord.LotteryRecordAgp
 * @ClassName: LotteryRecordAgp
 * @Description: TODO(购彩记录ActivityGroup)
 * @author 孔祥攀 <br/>
 * @date 2012-4-13 下午2:05:57
 * 
 */
public class LotteryRecordAgp extends ActivityGroup implements OnClickListener, OnCheckedChangeListener {
	public static int flag = Language.FLAG_FIVE;
	@SuppressWarnings("unused")
	private LinearLayout bodyView;
	private TabHost lotteryRecordTabHost;
	private Button btnBack;
	private RadioButton rbAll;
	private RadioButton rbUndone;
	private RadioButton rbWinning;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lotteryrecord_agp);
		lotteryRecordTabHost = (TabHost) findViewById(R.id.lotteryrecord_agp_tabhost);
		lotteryRecordTabHost.setup(LotteryRecordAgp.this.getLocalActivityManager());
		rbAll = (RadioButton) findViewById(R.id.lotteryrecord_agp_rb_all);
		rbAll.setOnClickListener(this);
		rbWinning = (RadioButton) findViewById(R.id.lotteryrecord_agp_rb_winning);
		rbWinning.setOnClickListener(this);
		rbUndone = (RadioButton) findViewById(R.id.lotteryrecord_agp_rb_undone);
		rbUndone.setOnClickListener(this);
		// 全部彩种标签 未结投注
		TabSpec undoneRecordTS = lotteryRecordTabHost.newTabSpec("UNDONE_LOTTERYRECORD");
		undoneRecordTS.setIndicator("未结投注");
		undoneRecordTS.setContent(new Intent(this, LotteryRecordUndoneAct.class));
		lotteryRecordTabHost.addTab(undoneRecordTS);

		// 全部彩种标签 最近中奖
		TabSpec winningRecordTS = lotteryRecordTabHost.newTabSpec("WINNING_LOTTERYRECORD");
		winningRecordTS.setIndicator("最近中奖");
		winningRecordTS.setContent(new Intent(this, LotteryRecordWinningAct.class));
		lotteryRecordTabHost.addTab(winningRecordTS);

		// 全部彩种标签 全部购彩
		TabSpec totalRecordTS = lotteryRecordTabHost.newTabSpec("TOTAL_LOTTERYRECORD");
		totalRecordTS.setIndicator("全部购彩");
		totalRecordTS.setContent(new Intent(this, LotteryRecordTotalAct.class));
		lotteryRecordTabHost.addTab(totalRecordTS);

		lotteryRecordTabHost.setCurrentTab(0);

		btnBack = (Button) findViewById(R.id.lotteryrecord_agp_btn_back);
		btnBack.setOnClickListener(this);

		final TabWidget tab_widget = lotteryRecordTabHost.getTabWidget();
		int width = 45;
		int height = 50;

		for (int i = 0; i < tab_widget.getChildCount(); i++) {
			tab_widget.getChildAt(i).getLayoutParams().height = height;
			tab_widget.getChildAt(i).getLayoutParams().width = width;
		}
	}

	public static boolean isCanClick = true;

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

		Message msg = new Message();
		msg.what = Config.DO_REFRESH;

		switch (v.getId()) {
		case R.id.lotteryrecord_agp_rb_undone:
			if (isCanClick) {
				lotteryRecordTabHost.setCurrentTab(0);
				LotteryRecordUndoneAct.handlerGetTotalLotteryRecord.sendMessage(msg);
				isCanClick = false;
			}

			break;

		case R.id.lotteryrecord_agp_rb_winning:
			if (isCanClick) {
				lotteryRecordTabHost.setCurrentTab(1);
				LotteryRecordWinningAct.handlerGetTotalLotteryRecord.sendMessage(msg);
				isCanClick = false;
			}

			break;

		case R.id.lotteryrecord_agp_rb_all:
			if (isCanClick) {
				lotteryRecordTabHost.setCurrentTab(2);
				LotteryRecordTotalAct.handlerGetTotalLotteryRecord.sendMessage(msg);
				isCanClick = false;
			}

			break;

		case R.id.lotteryrecord_agp_btn_back:
			Intent intent = new Intent();
			Bundle bundle=new Bundle();
			bundle.putInt("CURRENT_TAB_NUM", 0);
			intent.putExtras(bundle);
			intent.setClass(LotteryRecordAgp.this, SportteryFootballAgp.class);
			startActivity(intent);

			break;

		default:

			break;

		}
	}

	// 将menu键点击事件返回给父activity处理
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_MENU) {
			Activity parent = getParent();
			if (parent != null) {
				parent.onKeyDown(keyCode, event);
				return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		this.unregisterReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver());
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		this.registerReceiver(ConnectionChangeReceiver.getConnectionChangeReceiver(), ConnectionChangeReceiver.getIntentFilter());
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		// TODO Auto-generated method stub

	}
}
